package com.zh.login.ui

import android.content.Intent
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.LogUtils
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.CollapsingToolbarLayout
import com.zh.common.base.BaseActivity
import com.zh.common.ktx.gotoAct
import com.zh.common.utils.toast.ZToastUtils
import com.zh.config.ZjConfig
import com.zh.login.R
import com.zh.login.databinding.ActivityLoginBinding
import java.lang.Math.abs


@Route(path = ZjConfig.LoginActivity)
class LoginActivity: BaseActivity<ActivityLoginBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        ZToastUtils.showShort(intent.getStringExtra("name"))
        gotoAct(sdActivity::class.java)
        var afterY = 0
        viewBinding.appBarLayout.addOnOffsetChangedListener(object :
            AppBarLayout.OnOffsetChangedListener {
            override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) {
                LogUtils.eTag("verticalOffset  $verticalOffset")
                LogUtils.eTag("toolbarLayout  ${viewBinding.toolbarLayout.measuredHeight}")
                //当高度改变就重新设置子布局的高度
                /*var lps: CollapsingToolbarLayout.LayoutParams =
                    mBinding.changeView.layoutParams as CollapsingToolbarLayout.LayoutParams
                //得到滑动后可视子布局的高度
                lps.height = appBarLayout.measuredHeight - abs(verticalOffset)
                mBinding.changeView.layoutParams = lps*/
                val scale =
                    (viewBinding.changeView.measuredHeight + verticalOffset).toFloat() / viewBinding.changeView.measuredHeight
                viewBinding.changeView.scaleX = scale
                viewBinding.changeView.scaleY = scale
            }
        })
    }
}